package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;



   @GetMapping("index")
    public R index(){
       //查询前8条热门课程
       QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
       //根据id进行升序排行
       queryWrapper.orderByDesc("id");
       queryWrapper.last("limit 8");
       List<EduCourse> list = courseService.list(queryWrapper);

       //查询前4名讲师
       QueryWrapper<EduTeacher> Wrapper = new QueryWrapper<>();
       //根据id进行升序排行
       Wrapper.orderByDesc("id");
       Wrapper.last("limit 4");
       List<EduTeacher> teacherList = teacherService.list(Wrapper);
       return R.ok();
   }

}
